package com.tao.controller;

import com.tao.dto.AssistDto;
import com.tao.entity.Assist;
import com.tao.service.IAssistService;
import com.tao.utils.BeanCopyUtils;
import com.tao.utils.SecurityUtils;
import com.tao.vo.AssistDetailVo;
import com.tao.vo.AssistVo;
import com.tao.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zzp
 * @since 2023-05-07
 */
@RestController
@RequestMapping("/assist")
public class AssistController {

    @Resource
    private IAssistService assistService;


    /**
     * 根据求助id查询协助订单列表
     * @param helpId
     * @return
     */
    @GetMapping("/byHelp/{helpId}")
    public ResponseResult byHelp(@PathVariable Long helpId) {
        List<Assist> assists = assistService.byHelp(helpId);
        List<AssistVo> assistVos = BeanCopyUtils.copyBeanList(assists, AssistVo.class);

        return ResponseResult.okResult(assistVos);
    }


    /**
     * 查询我的所有协助订单
     */
    @GetMapping("/byAssistant")
    public ResponseResult byAssistant(@RequestParam Map<String,Object> map) {
        Map<String,Object> returnData;
        Integer pageNum = Integer.parseInt(map.get("pageNum").toString());
        Integer pageSize = Integer.parseInt(map.get("pageSize").toString());
        returnData = assistService.byAssistant(pageNum,pageSize,SecurityUtils.getUserId());
        return ResponseResult.okResult(returnData);
    }


    /**
     * 获取指定id的协助订单的详细信息
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public ResponseResult detail(@PathVariable Integer id) {
        Assist assist = assistService.detail(id);
        //封装表示层视图对象
        AssistDetailVo assistDetailVo = BeanCopyUtils.copyBean(assist, AssistDetailVo.class);
        return ResponseResult.okResult(assistDetailVo);
    }

    /**
     * 审核订单
     * @param assistDto
     * @return
     */
    @PutMapping("/verify")
    public ResponseResult verify(@RequestBody AssistDto assistDto) {
        return assistService.verify(assistDto);
    }

    /**
     * 完成订单
     * @param assistDto
     * @return
     */
    @PutMapping("/finish")
    public ResponseResult finish(@RequestBody AssistDto assistDto) {
        return assistService.finish(assistDto);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        return assistService.delete(id);
    }


    /**
     * 根据求助id新增协助订单
     * @param helpId
     * @return
     */
    @PostMapping("/{helpId}")
    public ResponseResult add(@PathVariable Long helpId){
        return assistService.add(helpId);
    }
}
